package com.guchenghao.controller;

import com.guchenghao.entity.Article;
import com.guchenghao.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @User 20675
 * @Author gch
 * @Date 2025/3/31 19:40
 * @Description <br />
 * <p>
 * <br />
 */
@Controller
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    // 跳转到 文章详情 页面
    @GetMapping("/article")
    public String toArticle() {
        return "article";
    }

    // 根据文章 id 展示单篇文章
    @GetMapping("/article/show/{id}")
    @ResponseBody
    public Article showArticle(@PathVariable Integer id) {
        return articleService.showArticle(id);
    }

    // 根据文章 id 展示单篇文章，并附带评论与评论的用户信息
    @GetMapping("/article/show/comments/{id}/{commentPageNum}/{commentPageSize}")
    @ResponseBody
    public Article showArticleWithComment(
            @PathVariable Integer id,
            @PathVariable Integer commentPageNum,
            @PathVariable Integer commentPageSize) {
        return articleService.showArticleWithComment(id, commentPageNum, commentPageSize);
    }
}
